package com.demo.rydemo.d_role.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.demo.rydemo.d_role.entity.DRole;
import com.demo.rydemo.d_role.service.IDRoleService;
import com.demo.rydemo.d_role.vo.DRoleVO;
import com.demo.rydemo.result.AjaxResult;
import com.demo.rydemo.result.CoreController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ry
 * @since 2020-08-25
 */
@Api(tags = "角色管理接口")
@RestController
@RequestMapping("/d_role/d-role")
public class DRoleController extends CoreController {

    @Autowired
    IDRoleService idRoleService;

    @Autowired
    AjaxResult ajaxResult;

    @ApiOperation("资源查询列表")
    @GetMapping("/getRoleList")
    AjaxResult getRoleList(DRoleVO dRoleVO) {
        IPage<DRole> page = idRoleService.getRoleList(dRoleVO);

        return ajaxResult.success(page);
    }

    @ApiOperation("添加角色")
    @PostMapping("/addRole")
    AjaxResult addRole(@RequestBody DRole dRole){
        Boolean flag = false;
        flag = idRoleService.addRole(dRole);
        if (flag){
            return ajaxResult.success(flag);
        }
        return ajaxResult.error("失败，请联系管理员");
    }

    @ApiOperation("修改角色")
    @PostMapping("/updRole")
    AjaxResult updRole(@RequestBody DRole dRole){
        Boolean flag = false;
        flag = idRoleService.updateById(dRole);
        if(flag){
            return ajaxResult.success("修改角色成功!");
        }
        return ajaxResult.error("操作失败,请联系管理员");
    }

    @ApiOperation("删除角色")
    @PostMapping("/delRole/{id}")
    AjaxResult delRole(@PathVariable String id){
        Boolean flag = false;
        flag = idRoleService.removeById(id);
        if(flag){
            return ajaxResult.success("删除角色成功!");
        }
        return ajaxResult.error("操作失败,请联系管理员");
    }
}
